<template>
  <ul class="right-list-container">
    <li v-for="item in list" :key="item.id">
      <span
        class="name"
        :class="{
          selected: item.selected,
        }"
        @click="handleClick(item)"
        >{{ item.name }}</span
      >
      <span
        class="count"
        :class="{
          selected: item.selected,
        }"
        v-if="item.total"
        @click="handleClick(item)"
        >{{ item.total }}篇</span
      >
      <RightList
        @click="handleClick"
        v-if="item.children"
        :list="item.children"
      />
    </li>
  </ul>
</template>

<script>
export default {
  name: "RightList",
  props: {
    list: {
      type: Array,
      require: true,
    },
  },
  methods: {
    handleClick(item) {
      if (!item.selected) {
        this.$emit("click", item);
      }
    },
  },
};
</script>

<style scoped lang="less">
@import "../styles/color.less";

.right-list-container {
  width: 100%;
  li {
    line-height: 40px;
    cursor: pointer;
    .right-list-container{
      margin-left: 1em;
    }
    .count{
      margin-left: 20px;
      color: @gray;
    }
    .selected {
      color: @warn;
      font-weight: bold;
    }
  }
}
</style>